﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Serilog;

namespace Workflow.Api.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class IFreeSqlController : ControllerBase
    {
        private IServiceProvider serviceProvider;

        public IFreeSqlController(IServiceProvider _serviceProvider  )
        {
            serviceProvider= _serviceProvider;
        }

        [HttpGet]
        public string GetCurrentFreeSqlConn()
        {
            IdleBus<IFreeSql> idleBus =  serviceProvider.GetRequiredService<IdleBus<IFreeSql>>();
            string conStr = idleBus.Get().Ado.ConnectionString;
            Log.Information($"当前数据库连接语句---- {conStr}");

            string updateStr=idleBus.ChangeDatabase("ConnDB_Mysql_Work").Get().Ado.ConnectionString;

            Log.Information($"当前数据库连接语句---- {updateStr}");
            return conStr;
        }
    }
}
